package com.example.jdbc.framework.core.common.jdbc.datasource;

import org.aspectj.lang.JoinPoint;

/**
 * @Classname DynamicDataSourceEntry
 * @Date 2019/5/16 22:56
 * @Author admin
 * @Description TODO
 */
public class DynamicDataSourceEntry {

    public final static String DEFAULT_SOURCE = null;

    private final static ThreadLocal<String> local = new ThreadLocal<>();

    public void clear() {
        local.remove();
    }

    public String get() {
        return local.get();
    }

    public void restore(JoinPoint point) {
        local.set(DEFAULT_SOURCE);
    }

    public void restore() {
        local.set(DEFAULT_SOURCE);
    }

    public void set(String source) {
        local.set(source);
    }

    public void set(int year) {
        local.set("DB_" + year);
    }

}
